package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.NewsAuthDto;
import com.heima.media.dto.WmNewsDto;
import com.heima.media.dto.WmNewsPageDto;
import com.heima.media.dto.WmNewsVo;
import com.heima.media.service.IWmNewsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: heima-leadnews
 * @BelongsPackage: com.heima.media.controller
 * @Author: wangjian
 * @CreateTime: 2022-07-01  20:18
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
@CrossOrigin
public class WmNewsController {
    @Autowired
    private IWmNewsService wmNewsService;

    @PostMapping("/list")
    public ResponseResult listByCondition(@RequestBody WmNewsPageDto dto) {
        return wmNewsService.listByCondition(dto);
    }
/**
 * @description: 查询文章
 * @author: wangjian
        * @date: 2022/7/1 20:23
 * @param: id
 * @return: com.heima.common.dto.ResponseResult
 **/
    @GetMapping("/{id}")
    public ResponseResult getById(@PathVariable("id") Integer id) {
        com.heima.media.entity.WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }
    /**
     * @description: 新增文章
     * @author: wangjian
            * @date: 2022/7/1 20:22
     * @param: dto
     * @return: com.heima.common.dto.ResponseResult
     **/
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }
    /**
     * @description: 查询文章列表
     * @author: wangjian
            * @date: 2022/7/3 22:46
     * @param: dto
     * @return: com.heima.common.dto.ResponseResult
     **/
    @PostMapping("/findPageByName")
    public ResponseResult findPageByName(@RequestBody NewsAuthDto dto){
        return wmNewsService.findPageByName(dto);
    }
 /**
  * @description: 查询文章详情(带作者信息)
  * @author: wangjian
         * @date: 2022/7/3 22:46
  * @param: id
  * @return: com.heima.common.dto.ResponseResult<WmNewsVo>
  **/
    @GetMapping("/findNewsVoById/{id}")
    public ResponseResult<WmNewsVo> findNewsVoById(@PathVariable("id") Integer id){
        return wmNewsService.findNewsVoById(id);
    }
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto dto) {
        return wmNewsService.auth(dto, 0);
    }
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto dto) {
        return wmNewsService.auth(dto, 1);
    }
    @PutMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }
}
